﻿

CREATE proc dbo.MoveFile
	@SourceFile	nvarchar(400), -- incl. full path,
	@TargetFile nvarchar(400),
	@CopyState	bit = 0 output
as
begin
	declare @command	nvarchar(4000) = 'MOVE "';

	if @SourceFile is null
	begin
		raiserror('SourceFile is null', 16, 1)
	end

	if @TargetFile is null
	begin
		raiserror('TargetFile is null', 16, 1)
	end

	set @command += @SourceFile + '" "' + @TargetFile + '"';
	begin try
		print @command;
		EXEC master.dbo.xp_cmdshell @command;
		
	end try
	begin catch
		print ERROR_MESSAGE();
		raiserror('Error on create a new calculation file.', 16,1)
		return 1;
	end catch
	set @CopyState = 1;
end